package com.kuaifawu.lwnlawyerclient.Lib;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.kuaifawu.lwnlawyerclient.R;

/**
 * Created by zhangminglei on 15/3/11.
 */
public class ToastView_custom extends View {
    private Toast mToast;

    public ToastView_custom(Context context) {
        super(context);
    }

    public void showCustom(Activity activity ,String string_content) {
        LayoutInflater inflater = activity.getLayoutInflater();
        View view_custom = inflater.inflate(R.layout.toast_custom, null);
        mToast = new Toast(activity);
        //mToast.setDuration(Toast.LENGTH_SHORT);
       // mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setView(view_custom);
        mToast.show();

        Message delayMsg = m_Handler.obtainMessage(1);
        m_Handler.sendMessageDelayed(delayMsg, 1000);


        //ImageView imageView_sign = (ImageView) view_custom.findViewById(R.id.toast_image);
        TextView textView_content = (TextView) view_custom.findViewById(R.id.toast_text);

        //imageView_sign.setImageDrawable(drawable_sign);
        textView_content.setText(string_content);
    }

    public void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }

    private Handler m_Handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            switch (msg.what) {
                case 0:
                    break;
                case 1: {
                    cancelToast();
                    break;
                }
            }
        }
    };
}
